using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class MemberAlertPreferenceDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public MemberAlertPreferenceDA()
		{
		}

		public MemberAlertPreferenceDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the MemberAlertPreference table.
		/// </summary>
		public  int Insert(MemberAlertPreference memberAlertPreference)
		{
			ValidationUtility.ValidateArgument("memberAlertPreference", memberAlertPreference);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", memberAlertPreference.TenantID),
				new SqlParameter("@ProfileID", memberAlertPreference.ProfileID),
				new SqlParameter("@AlertID", memberAlertPreference.AlertID),
				new SqlParameter("@IsEnabled", memberAlertPreference.IsEnabled)
			};

			memberAlertPreference.AlertPreferenceID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "MemberAlertPreferenceInsert", parameters));
			return memberAlertPreference.AlertPreferenceID;
		}

		/// <summary>
		/// Updates a record in the MemberAlertPreference table.
		/// </summary>
		public  int Update(MemberAlertPreference memberAlertPreference)
		{
			ValidationUtility.ValidateArgument("memberAlertPreference", memberAlertPreference);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@AlertPreferenceID", memberAlertPreference.AlertPreferenceID),
				new SqlParameter("@TenantID", memberAlertPreference.TenantID),
				new SqlParameter("@ProfileID", memberAlertPreference.ProfileID),
				new SqlParameter("@AlertID", memberAlertPreference.AlertID),
				new SqlParameter("@IsEnabled", memberAlertPreference.IsEnabled)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberAlertPreferenceUpdate", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberAlertPreference table by its primary key.
		/// </summary>
		public  int Delete(int alertPreferenceID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@AlertPreferenceID", alertPreferenceID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberAlertPreferenceDelete", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberAlertPreference table by a foreign key.
		/// </summary>
		public  int DeleteAllByAlertID(int alertID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@AlertID", alertID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberAlertPreferenceDeleteAllByAlertID", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberAlertPreference table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberAlertPreferenceDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberAlertPreference table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberAlertPreferenceDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects a single record from the MemberAlertPreference table.
		/// </summary>
		public  MemberAlertPreference Select(int alertPreferenceID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@AlertPreferenceID", alertPreferenceID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberAlertPreferenceSelect", parameters))
			{
				if (dataReader.Read())
				{
					return MakeMemberAlertPreference(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the MemberAlertPreference table.
		/// </summary>
		public  List<MemberAlertPreference> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberAlertPreferenceSelectAll", parameters))
			{
				List<MemberAlertPreference> memberAlertPreferenceList = new List<MemberAlertPreference>();
				while (dataReader.Read())
				{
					MemberAlertPreference memberAlertPreference = MakeMemberAlertPreference(dataReader);
					memberAlertPreferenceList.Add(memberAlertPreference);
				}

				return memberAlertPreferenceList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberAlertPreference table by a foreign key.
		/// </summary>
		public  List<MemberAlertPreference> SelectAllByAlertID(int alertID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@AlertID", alertID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberAlertPreferenceSelectAllByAlertID", parameters))
			{
				List<MemberAlertPreference> memberAlertPreferenceList = new List<MemberAlertPreference>();
				while (dataReader.Read())
				{
					MemberAlertPreference memberAlertPreference = MakeMemberAlertPreference(dataReader);
					memberAlertPreferenceList.Add(memberAlertPreference);
				}

				return memberAlertPreferenceList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberAlertPreference table by a foreign key.
		/// </summary>
		public  List<MemberAlertPreference> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberAlertPreferenceSelectAllByProfileID", parameters))
			{
				List<MemberAlertPreference> memberAlertPreferenceList = new List<MemberAlertPreference>();
				while (dataReader.Read())
				{
					MemberAlertPreference memberAlertPreference = MakeMemberAlertPreference(dataReader);
					memberAlertPreferenceList.Add(memberAlertPreference);
				}

				return memberAlertPreferenceList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberAlertPreference table by a foreign key.
		/// </summary>
		public  List<MemberAlertPreference> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberAlertPreferenceSelectAllByTenantID", parameters))
			{
				List<MemberAlertPreference> memberAlertPreferenceList = new List<MemberAlertPreference>();
				while (dataReader.Read())
				{
					MemberAlertPreference memberAlertPreference = MakeMemberAlertPreference(dataReader);
					memberAlertPreferenceList.Add(memberAlertPreference);
				}

				return memberAlertPreferenceList;
			}
		}

		/// <summary>
		/// Creates a new instance of the MemberAlertPreference class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  MemberAlertPreference MakeMemberAlertPreference(SqlDataReader dataReader)
		{
			MemberAlertPreference memberAlertPreference = new MemberAlertPreference();
			memberAlertPreference.AlertPreferenceID = SqlClientUtility.GetInt32(dataReader, "AlertPreferenceID", 0);
			memberAlertPreference.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			memberAlertPreference.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			memberAlertPreference.AlertID = SqlClientUtility.GetInt32(dataReader, "AlertID", 0);
			memberAlertPreference.IsEnabled = SqlClientUtility.GetBoolean(dataReader, "IsEnabled", false);

			return memberAlertPreference;
		}

		#endregion
	}
}
